package ping.client;

/**
 * 延时计算
 */
public class TimeToLive {
	private long[] ttls;
	
	public TimeToLive(long[] ttls) {
		this.ttls = ttls;
	}
	
	public void setTtls(long[] ttls) {
		this.ttls = ttls;
	}
	
	public long[] getTtls() {
		return ttls;
	}
	
	/**
	 * 计算最大延时
	 * @return
	 */
	public long maxTtl() {
		long max = 0;
		for (long ttl : ttls) {
			if (ttl == -1) continue;
			else if (max < ttl) max = ttl;
		}
		return max;
	}
	
	/**
	 * 计算最小延时
	 * @return
	 */
	public long minTtl() {
		long min = 1001;
		for (long ttl : ttls) {
			if (ttl == -1) continue;
			else if (min > ttl) min = ttl;
		}
		return min;
	}
	
	/**
	 * 计算延时总和
	 * @return
	 */
	public long ttlSum() {
		long sum = 0;
		for (long ttl : ttls) {
			if (ttl == -1) continue;
			sum += ttl;
		}
		return sum;
	}
	
	/**
	 * 计算平均延时
	 * @return
	 */
	public long ttlAverage() {
		return this.ttlSum() / this.ttls.length;
	}
}
